﻿@using Hotel.Application;
@model QueryDto
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 内容系统 - 文章列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="~/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="~/layuiadmin/style/admin.css" media="all">    
</head>
<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <table class="layui-hide" id="data-list" lay-filter="data-list"></table>
                <script type="text/html" id="table-content-list">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                </script>
            </div>
        </div>
    </div>


    <script type="text/html" id="toolbarDemo">
        <div class="layui-table-tool-temp">
            <div class="layui-inline" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
            </div>
            <div class="layui-inline" lay-event="update">
                <i class="layui-icon layui-icon-edit"></i>
            </div>
            <div class="layui-inline" lay-event="refresh">
                <i class="layui-icon layui-icon-refresh-3"></i>
            </div>
        </div>
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/layuiadmin/layui/layui.js"></script>
    <script src="~/moment.js/moment.min.js"></script>
    <script>        
        $(()=>{            
            $(".layui-table-body").css('overflow', 'visible');
            $(".layui-table-box").css('overflow', 'visible');
            $(".layui-table-view").css('overflow', 'visible');
            $(".layui-layer-content").css('overflow', 'visible');
        });
        var tableRender;
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index', //主入口模块
            treetable: 'treetable' //主入口模块
        }).use(['index', 'contlist', 'table', 'laydate', 'treetable'], function () {
            layer.load(1);
            var table = layui.table
                , form = layui.form;
            var laydate = layui.laydate;
            var treetable = layui.treetable;

            //执行一个laydate实例
            laydate.render({
                elem: '#StartTime' //指定元素
            });
            //执行一个laydate实例
            laydate.render({
                elem: '#EndTime' //指定元素
            });

            //监听搜索
            form.on('submit(LAY-app-contlist-search)', function (data) {
                var field = data.field;

                //执行重载
                table.reload('admin-list', {
                    where: field
                });

                return false;
            });

            var menuType = [];

            $.ajax({
                url: "@Url.Action("QueryByCache","Dic")",
                type: "get",
                data: { TypeCode: "MenuType" },
                async:false,
                success: function (d) {
                    menuType = d.map(x => {
                        return { TypeId: x.DicValue, MenuName: x.DicName, btn: x.DicCode };
                    });
                }
            })

            // 渲染表格
            tableRender = function () {
                treetable.render({
                    //height: 'full-160',
                    id: 'data-list',
                    treeColIndex: 1,	//树形图标显示在第几列
                    treeSpid: '0',		//最上级的父级id
                    treeIdName: 'MenuId',	//id字段的名称
                    treePidName: 'ParentId',	//父级节点字段
                    treeDefaultClose: false,	//是否默认折叠
                    treeLinkage: false,		//父级展开时是否自动展开所有子级
                    elem: '#data-list',	//表格id
                    url: '@Url.Action("Query")',
                    toolbar: '#toolbarDemo',
                    page: false,
                    cols: [[
                        { type: 'numbers', title: '序号' },
                        { field: 'MenuName', title: '菜单名称' },
                        { field: 'MenuRoute', title: '菜单路由' },
                        {
                            field: 'MenuType', width: 100, align: 'center', title: '菜单类型', templet: function (d) {
                                let obj = menuType.find(m => m.TypeId == parseInt(d.MenuType));
                                return `<div><button type="button" class="layui-btn layui-btn-xs ${obj.btn}">${obj.MenuName}</button></div>`;
                            }
                        },
                        { field: 'ParentId', title: '父ID', width: 190 },
                        { field: 'CreateName', align: 'center', title: '创建人', width: 90 },
                        { field: 'CreateTime', align: 'center', title: '创建时间',templet:function(d){
                                return moment(d.CreateTime).format("YYYY-MM-DD HH:mm:SS");
                            }
                        },
                        { fixed: 'right', title: '操作', align: 'center', toolbar: '#barDemo' }
                    ]],
                    //数据渲染完的回调
                    done: function () {
                        //关闭加载
                        layer.closeAll('loading');
                    }
                })
            };

            tableRender();

            //触发事件
            table.on('toolbar(data-list)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);

                switch (obj.event) {
                    case 'add':
                        layer.open({
                            type: 2
                            , title: '添加用户'
                            , content: '@Url.Action("Create")'
                            , maxmin: true
                            , scrollbar: false
                            , area: ['795px', '290px']
                            , btn: ['确定', '取消']
                            , yes: function (index, layero) {
                                //点击确认触发 iframe 内容中的按钮提交
                                var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                                submit.click();
                            }
                        });
                        break;
                    case 'delete':
                        layer.confirm('真的删除行么', function (index) {
                            //向服务端发送删除指令
                            $.ajax({
                                url: "@Url.Action("Delete")",
                                type: "delete",
                                data: { entities: checkStatus.data },
                                success: function (e) {
                                    //执行重载
                                    table.reload('admin-list');
                                    layer.close(index);
                                }
                            });
                        });
                        break;
                    case 'update':
                        if (checkStatus.data.length > 1 || checkStatus.data.length <= 0) {
                            layer.msg("只能选择一条记录", { icon: 5 });
                            return;
                        }
                        layer.open({
                            type: 2
                            , title: '编辑用户'
                            , content: '@Url.Action("Edit")/' + checkStatus.data[0].AdminId
                            , maxmin: true
                            , area: ['450px', '280px']
                            , btn: ['确定', '取消']
                            , yes: function (index, layero) {
                                //点击确认触发 iframe 内容中的按钮提交
                                var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                                submit.click();
                            }
                        });
                        break;
                };
            });

            //工具条事件
            table.on('tool(admin-list)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

                if (layEvent === 'detail') { //查看
                    //do somehing
                } else if (layEvent === 'del') { //删除
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url: "@Url.Action("Delete")",
                            type: "get",
                            data: { id: data.AdminId },
                            success: function (e) {
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                layer.close(index);
                            }
                        });
                    });
                } else if (layEvent === 'edit') { //编辑
                    layer.open({
                        type: 2
                        , title: '编辑用户'
                        , content: '@Url.Action("Edit")/' + data.AdminId
                        , maxmin: true
                        , area: ['450px', '280px']
                        , btn: ['确定', '取消']
                        , yes: function (index, layero) {
                            //点击确认触发 iframe 内容中的按钮提交
                            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                            submit.click();
                        }
                    });
                }
            });
        });
    </script>
</body>
</html>

